package concurrency;


import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

public class Test implements Runnable{

    public static void main(String[] args) {
        Executor threadPool = Executors.newFixedThreadPool(100);
        CountDownLatch countDownLatch = new CountDownLatch(100);
        for (int i=0;i<100;i++){
            threadPool.execute(new Runnable() {
                @Override
                public void run() {
                    try {
                        countDownLatch.countDown();
                        countDownLatch.await();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName()+","+Singleton.getInstance());
                }
            });
        }
//        Test test1 = new Test();
//        Test test2 = new Test();
//        Thread thread1 = new Thread(test1);
//        Thread thread2 = new Thread(test2);
//        thread1.start();
//        thread2.start();
    }

    @Override
    public void run() {
        for (int i=0;i<100;i++){
            System.out.println("第"+i+"次："+Singleton.getInstance());
        }
    }
}
